cmake_minimum_required(VERSION 2.8)

project(surcloud-gateway C CXX)

set(Boost_NO_BOOST_CMAKE 1)

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "debug")
endif()

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -Wall -std=c++0x -D_FILE_OFFSET_BITS=64")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O1 -finline-limit=1000 -DNDEBUG")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR})

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})

# borZoi
include_directories(contrib/borZoi-1.0.2/src)
if (NOT DEPS_DIR)
    set (DEPS_DIR ${PROJECT_SOURCE_DIR}/../)
endif()

# onion library
if (NOT ONION_DIR)
    set(ONION_DIR ${DEPS_DIR}/onion)
endif()
include_directories(${ONION_DIR})
include_directories(${ONION_DIR}/src)
link_directories(${ONION_DIR}/build/lib)

# json library
if (NOT JSONCPP_DIR)
    set(JSONCPP_DIR ${DEPS_DIR}/jsoncpp)
endif()
include_directories(${JSONCPP_DIR}/include)
link_directories(${JSONCPP_DIR}/build/src/lib_json)

# set rpath
SET(CMAKE_INSTALL_RPATH "$ORIGIN")

# Which backend will be used?
# cmake -DBACKEND=PER --> Personal Cloud Service
# cmake -DBACKEND=ENT --> Enterprise Cloud Service
if (${CLOUD_BACKEND} STREQUAL "PER") 
    add_definitions(-DPERSONAL_CLOUD_BACKEND=1)
    message("Use personal cloud backend")
else()
    add_definitions(-DPERSONAL_CLOUD_BACKEND=0)
    message("Use enterprise cloud backend")
endif()

# Git revision
exec_program(
    "git"
    ${CMAKE_CURRENT_SOURCE_DIR}
    ARGS "rev-parse HEAD"
    OUTPUT_VARIABLE VERSION_SHA1 )

add_definitions(-DGIT_SHA1="${VERSION_SHA1}")

add_subdirectory(gwbase)
add_subdirectory(surbasic)
# add_subdirectory(gwlib)
add_subdirectory(dicom)
add_subdirectory(contrib)
add_subdirectory(tests)
add_subdirectory(bench)
add_subdirectory(ukey)
# add_subdirectory(surbasic)
